﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using App.Interface;
using App.Model;
using Newtonsoft.Json;

namespace App.Realization
{
    public class MyCaoZuotmpl : IMyCaoZuo
    {
        public string CreateMyGongZuoJiHua(string username, string sssj)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/CreateMyKaoHebiao?username=" + username + "&sssj=" + sssj);
            return reslut;
        }

        public string GetMyGongZuoJiHuas(string username)
        {
            dynamic obj = new { username = username };
            string postData = JsonConvert.SerializeObject(obj);
            var result = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/GetMyKaoHeBiaos", postData);
            return result;
        }

        public string GetMyLiShiGongZuoJiHuas(string username)
        {
            dynamic obj = new { username = username };
            string postData = JsonConvert.SerializeObject(obj);
            var result = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/GetLiShiMyKaoHeBiaos", postData);
            return result;
        }
        public void UpdateMyGongZuoJiHua(string str)
        {
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/UpdateMyKaoHeBiao", str);
        }

        public void DelMyKaoHeBiao(int khbid)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/DelMyKaoHeBiao?khbid=" + khbid);
        }

        public string GetMyKaoHeBiaoInfo(int khbid)
        {
            dynamic obj = new { khbid = khbid };
            string postData = JsonConvert.SerializeObject(obj);
            var result = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/GetMyKaoHeBiaoInfo", postData);
            Newtonsoft.Json.Converters.IsoDateTimeConverter convert = new Newtonsoft.Json.Converters.IsoDateTimeConverter();
            convert.DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff";
            var DynamicObject = JsonConvert.DeserializeObject<dynamic>(result, convert);
            var tt = Mappeing.ToMyKaoHeBiao(DynamicObject);
            string mykaohebiaostr = JsonConvert.SerializeObject(tt);
            return mykaohebiaostr;
        }
        /// <summary>
        /// 提交工作计划
        /// </summary>
        /// <param name="khbid"></param>
        public void UpdateTiJiaoKaoHeBiao(int khbid)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/UpdateTiJiao?khbid=" + khbid);
        }

        public string GetGongZuoJiHuas_Bymbid(int mbid)
        {
            dynamic obj = new { mbid = mbid };
            string postData = JsonConvert.SerializeObject(obj);
            var result = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/GetGongZuoJiHuasBymbid", postData);
            return result;
        }

        public void UpdateGongZuoJiHuaOK(string username, int mkhbid, string yijian)
        {
            //var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/TongGuoShenHe?username=" + username + "&mkhbid=" + mkhbid);
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/UpdateMyKaoHeBiaoState?username=" + username + "&khbid=" + mkhbid + "&state=5" + "&yijian=" + yijian);
            //return reslut;
        }

        //public void UpdateGongZuoJiHuaReject(int mkhbid)
        //{
        //    var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/BoHuiShenHe?mkhbid=" + mkhbid);
        //}

        public void UpdateGongZuoJiHuaRejectByusername(string username)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/Admin/RejectGZJHByusername?username=" + username);
        }

        public void CreateLinShiGongZuo(string username, string gznr, string gzbz, int mkhbid)
        {
            dynamic obj = new { username = username, gznr = gznr, gzbz = gzbz, mkhbid = mkhbid };
            string postData = JsonConvert.SerializeObject(obj);
            var result = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/CreateLinShiGongZuo", postData);
        }
        public void DelLinShiGongZuo(int mkhbid, int twoid)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/DelLinShiGongZuo?mkhbid=" + mkhbid + "&twoid=" + twoid);
        }

        public void UploadFile(int mkhbid, int twoid, string guid, string filepath, string uploadtitle, string uploadfileHash)
        {
            dynamic obj = new { fileHash = uploadfileHash, fjmc = uploadtitle, path = filepath, fileguid = guid, twoid = twoid, mkhbid = mkhbid };
            string postData = JsonConvert.SerializeObject(obj);
            var result = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/UploadFile", postData);
        }

        public string GetFileList(int mkhbid, int twoid)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/GetFileList?mkhbid=" + mkhbid + "&twoid=" + twoid);
            return reslut;
        }
        public void DelFile(int mkhbid, int twoid, int fjid)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/DelUploadFile?mkhbid=" + mkhbid + "&twoid=" + twoid + "&fjid=" + fjid);
        }

        public string getGongZuoChengDanRen(string username)
        {
            dynamic obj = new { username = username };
            string postData = JsonConvert.SerializeObject(obj);
            var result = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/getGongZuoChengDanRen", postData);
            return result;
        }

        public string saveKaoHeNeiRongTow(string model, int mkhbid, int oneid, string username)
        {
            MyKaoHeBiaotwo tow = JsonConvert.DeserializeObject<MyKaoHeBiaotwo>(model);
            dynamic DynamicObject = new ExpandoObject();
            DynamicObject.fenzhi = tow.fz;
            DynamicObject.shunxu = tow.sx;
            DynamicObject.gzcdrid = tow.gzcdrid;
            DynamicObject.cjrid = tow.cjrid;
            DynamicObject.cjsj = DateTime.Now;
            DynamicObject.isedit = tow.IsEdit;
            DynamicObject.iswc = tow.Iswc;
            DynamicObject.jssj = tow.gzjhwcsj;
            DynamicObject.kssj = tow.gzjhkssj;
            DynamicObject.laiyuan = tow.lyid;
            DynamicObject.ljcs = tow.ljcs;
            DynamicObject.nr = tow.mbnr;
            DynamicObject.pcid = tow.twoid;
            DynamicObject.wcqk = tow.gzjhwcqk;
            DynamicObject.zhou = tow.zhou;
            DynamicObject.zpf = tow.zp;
            DynamicObject.PersonalAnswers = new List<dynamic>();
            dynamic o = new ExpandoObject();
            o.fenzhi = tow.fz;
            o.html = "";
            //o.paid = item3.paid;
            o.shunxu = 1;
            o.tips = "";
            DynamicObject.PersonalAnswers.Add(o);
            dynamic obj = new { model = DynamicObject, mkhbid = mkhbid, pathid = oneid, username = username };
            string postData = JsonConvert.SerializeObject(obj);
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/saveKaoHeNeiRongTow", postData);
            return reslut;
        }

        public void delKaoHeNeiRongTow(int towid, int mkhbid, int oneid, string username)
        {
            dynamic obj = new { towid = towid, mkhbid = mkhbid, pathid = oneid, username = username };
            string postData = JsonConvert.SerializeObject(obj);
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/delKaoHeNeiRongTow", postData);
        }

        public void updateKaoHeNeiRongTow(string model, int mkhbid, int oneid, string username)
        {
            MyKaoHeBiaotwo tow = JsonConvert.DeserializeObject<MyKaoHeBiaotwo>(model);
            dynamic DynamicObject = new ExpandoObject();
            DynamicObject.pcid = tow.twoid;
            DynamicObject.fenzhi = tow.fz;
            DynamicObject.shunxu = tow.sx;
            DynamicObject.gzcdrid = tow.gzcdrid;
            DynamicObject.cjrid = tow.cjrid;
            DynamicObject.cjsj = DateTime.Now;
            DynamicObject.isedit = tow.IsEdit;
            DynamicObject.iswc = tow.Iswc;
            DynamicObject.jssj = tow.gzjhwcsj;
            DynamicObject.kssj = tow.gzjhkssj;
            DynamicObject.laiyuan = tow.lyid;
            DynamicObject.ljcs = tow.ljcs;
            DynamicObject.nr = tow.mbnr;
            DynamicObject.pcid = tow.twoid;
            DynamicObject.wcqk = tow.gzjhwcqk;
            DynamicObject.zhou = tow.zhou;
            DynamicObject.zpf = tow.zp;
            DynamicObject.PersonalAnswers = new List<dynamic>();
            dynamic o = new ExpandoObject();
            o.fenzhi = tow.fz;
            o.html = "";
            //o.paid = item3.paid;
            o.shunxu = 1;
            o.tips = "";
            DynamicObject.PersonalAnswers.Add(o);
            dynamic obj = new { model = DynamicObject, mkhbid = mkhbid, pathid = oneid, username = username };
            string postData = JsonConvert.SerializeObject(obj);
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/updateKaoHeNeiRongTow", postData);
        }
        public string 获取没有分配周数的月工作计划(int khbid)
        {
            dynamic obj = new { khbid = khbid };
            string postData = JsonConvert.SerializeObject(obj);
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/GetWeiFenPeiYueJiHua", postData);
            return reslut;
        }

        public string 获取已分配周数的周计划(int khbid, int 周数)
        {
            dynamic obj = new { khbid = khbid, 周数 = 周数 };
            string postData = JsonConvert.SerializeObject(obj);
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/GetYiFenPeiZhouJiHua", postData);
            return reslut;
        }

        public void 生成单条周计划(int khbid, int twoid, int 周数)
        {
            dynamic obj = new { khbid = khbid, twoid = twoid, 周数 = 周数 };
            string postData = JsonConvert.SerializeObject(obj);
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/CreateDanTiaoZhouJiHua", postData);
        }

        public void 取消单条周计划(int khbid, int twoid, int 周数)
        {
            dynamic obj = new { khbid = khbid, twoid = twoid, 周数 = 周数 };
            string postData = JsonConvert.SerializeObject(obj);
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/DelDanTiaoZhouJiHua", postData);
        }

        public void UpdateGongZuoJiHuaWanChengZhuangTai(int khbid, int twoid, bool flag)
        {
            dynamic obj = new { khbid = khbid, twoid = twoid, flag = flag };
            string postData = JsonConvert.SerializeObject(obj);
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/UpdateGZJHWCQK", postData);
        }

        public string GetYueGongZuoZongJie(int khbid)
        {
            dynamic obj = new { khbid = khbid };
            string postData = JsonConvert.SerializeObject(obj);
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/getGongZuoZongJies", postData);
            return reslut;
        }

        public void delGongZuoJongJie(int khbid, int zjid)
        {
            dynamic obj = new { khbid = khbid, zjid = zjid };
            string postData = JsonConvert.SerializeObject(obj);
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/DelGongZuoZongJie", postData);
        }

        public void saveZouZongJie(int zongjielx, string zongjielxstr, string zongjienr, int khbid)
        {
            dynamic obj = new { zongjielx = zongjielx, zongjienr = zongjienr, khbid = khbid };
            string postData = JsonConvert.SerializeObject(obj);
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/CreateGongZuoZongJie", postData);
        }

        public void updateGongZuoZongJie(int zongjielx, string zongjielxstr, string zongjienr, int khbid, int zjtowid)
        {
            dynamic obj = new { khbid = khbid, zjtowid = zjtowid, zongjielx = zongjielx, zongjienr = zongjienr };
            string postData = JsonConvert.SerializeObject(obj);
            var reslut = HttpClientHelper.PostResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/UpdateGongZuoZongJie", postData);
        }

        public string TiJiaoKaoHeBiao(string username, int khbid)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/UpdateMyKaoHeBiaoState?username=" + username + "&khbid=" + khbid + "&state=5");
            return reslut;
        }

        public string BoHuiKaoHeBiao(string username, int khbid)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/UpdateMyKaoHeBiaoState?username=" + username + "&khbid=" + khbid + "&state=2");
            return reslut;
        }

        public string TongGuoKaoHeBiao(string username, int khbid)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/UpdateMyKaoHeBiaoState?username=" + username + "&khbid=" + khbid + "&state=5");
            return reslut;
        }

        public string CheHuiKaoHeBiao(string username, int khbid)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/UpdateMyKaoHeBiaoState?username=" + username + "&khbid=" + khbid + "&state=2");
            return reslut;
        }

        public string WanChengKaoHeBiao(string username, int khbid)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/UpdateMyKaoHeBiaoState?username=" + username + "&khbid=" + khbid + "&state=6");
            return reslut;
        }

        public void UpdateGongZuoJiHuaTuiHui(string username, int mkhbid, string yijian)
        {
            var reslut = HttpClientHelper.GetResponse(System.Web.Configuration.WebConfigurationManager.AppSettings["schoolapi"] + "/api/KaoHeBiaoCaoZuo/UpdateMyKaoHeBiaoState?username=" + username + "&khbid=" + mkhbid + "&state=2" + "&yijian=" + yijian);

        }
    }
}
